package com.front.web.lvyou_specialty_front.util;

import com.bootdo.common.config.ApplicationContextRegister;
import com.bootdo.common.utils.HttpUtil;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.system.domain.UserDO;
import com.bootdo.wx.domain.Config;
import com.bootdo.wx.service.ConfigService;
import com.bootdo.wx.service.impl.ConfigServiceImpl;
import com.front.web.wx.utils.MobanMessageUtils;

import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Set;

/**
  *
  * 发送模板消息
 　　* @author 郝江波
 　　* @date 2019/9/11 15:33
 　　*/
public class SendMbMessageUtils {
    /**
     * 发送模板消息
     */
//    public static void sendUserTempMessage(String orderNo, XinfangOrderLog xinfangOrderLog){
//        XinfangOrderService xinfangOrderService = ApplicationContextRegister.getBean(XinfangOrderServiceImpl.class);
//        XinfangOrder xinfangOrder = xinfangOrderService.getByOrderNo(orderNo);
//        sendUserTempMessage(xinfangOrder,xinfangOrderLog);
//    }

//    /**
//     * 发送模板消息
//     */
//    public static void sendUserTempMessage(XinfangOrder xinfangOrder, XinfangOrderLog xinfangOrderLog){
//        ConfigService configService = ApplicationContextRegister.getBean(ConfigServiceImpl.class);
//        if(null != xinfangOrder && StringUtils.isNotEmpty(xinfangOrder.getUserIdCard())){
//            if(StringUtils.isEmpty(xinfangOrder.getUserOpenId())){
//                XinfangVisitsUserService  xinfangVisitsUserService = ApplicationContextRegister.getBean(XinfangVisitsUserServiceImpl.class);
//                XinfangVisitsUser xinfangVisitsUser = xinfangVisitsUserService.getByIdCard(xinfangOrder.getUserIdCard());
//                xinfangOrder.setUserOpenId(xinfangVisitsUser.getOpenId());
//            }
//            Config config  = configService.getByUserId(9L);
//            try {
//                MobanMessageUtils.sendWxMobanXaoxi(config, xinfangOrder.getUserOpenId(), "cBMOskJHqi479Gs7hiR_ZzoRHicMgjL-DVNfL91uPg0",
//                        "案件有新动态", xinfangOrder.getTitle(), xinfangOrderLog.getContent(), "3", "4", "remark", "https://xiqing.1900th.com/f/xinfang/v1/visits/user/index");
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    }

//    public static void sendUserDefaultTempMessage(Map<XinfangVisitsUser, XinfangOrderLog> dealMap){
//        ConfigService configService = ApplicationContextRegister.getBean(ConfigServiceImpl.class);
//        Config config  = configService.getByUserId(9L);
//
//        Set<Map.Entry<XinfangVisitsUser, XinfangOrderLog>> entries = dealMap.entrySet();
//        for (Map.Entry one: entries) {
//            try {
//                if (StringUtils.isNotEmpty(((XinfangVisitsUser)one.getKey()).getOpenId())) {
//                    MobanMessageUtils.sendWxMobanXaoxi(config, ((XinfangVisitsUser)one.getKey()).getOpenId(), "cBMOskJHqi479Gs7hiR_ZzoRHicMgjL-DVNfL91uPg0",
//                            "案件有新动态", "", ((XinfangOrderLog)one.getValue()).getContent(), "3", "4", "remark", "https://xiqing.1900th.com/f/xinfang/v1/visits/user/index");
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//     }

    public static void sendUserDefaultTempMessage(UserDO userDO, Config config, String messageRedirectUrl) {
        try {
            MobanMessageUtils.sendWxMobanXaoxi(config, userDO.getWxGzhOpenId(), "dVNNPQRQ6Uv_TihYi5QtApNovWDv0hfF7uCEDngdsYw", "您有订单需要处理了", "",
                    "您有订单需要处理了", "3", "4", "remark", messageRedirectUrl + "?random="+ userDO.getMerchantId() + "&");
            System.err.println(messageRedirectUrl + "?uid="+ userDO.getMerchantId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
